
Version:=3.3.9
ModuleName:=ntop

rrdVersion:=1.3.6
rrdModuleName=rrdtool

Object:=$(ModuleName).tgz
ObjectDir:=$(ModuleName)-$(Version)
ObjectSource:=$(ModuleName)-$(Version).tar.gz

rrdObject:=$(rrdModuleName).tgz
rrdObjectDir:=$(rrdModuleName)-$(rrdVersion)
rrdObjectSource:=$(rrdModuleName)-$(rrdVersion).tar.gz

DependFiles:=GeoIPASNum.dat.gz GeoIP.tar.gz GeoLiteCity.dat.gz 

InstallDirTmp:=usr/local
InstallDir:=/$(InstallDirTmp)
InstallLib:=$(InstallDirTmp)/lib

Config:=./configure --disable-ipv6 --enable-sslv3 --enable-snmp --prefix=$(InstallDir)

Patch:= #patch -p0 < ntop-3.3.patch

.PHONY: all clean dist_clean

test:$(DependFiles)
	for i in $(DependFiles); do tar xzf $$i ; done

all:$(rrdObject) $(Object) 

$(rrdObject):$(rrdObjectSource)
	if [ -d usr ]; then rm -rf usr/*; else mkdir -p usr ;fi
	tar -xzf $(rrdObjectSource)
	cd $(rrdObjectDir) && ./configure --prefix=/usr/local 
	$(MAKE) -C $(rrdObjectDir) 
	$(MAKE) -C $(rrdObjectDir) install DESTDIR=`pwd`/
	rm -rf usr/local/share usr/local/man usr/local/include
	$(g_STRIP)
	find usr -name *.a -exec rm -rf {} \;
	tar -czf $(rrdObject) usr

$(Object):$(ObjectSource)
	tar -xzf $(ObjectSource)
	#if [ -d etc ]; then rm -rf etc/*; else mkdir -p etc ;fi
	#cp -rf ntop.conf etc
	$(Patch)
	cd $(ObjectDir) && ./autogen.sh && $(Config)
	$(MAKE) -C $(ObjectDir) 
	$(MAKE) -C $(ObjectDir) install DESTDIR=`pwd`/
	rm -rf usr/local/share/man
	if [ ! -d $(InstallLib) ]; then mkdir -p $(InstallLib); fi
	cp -afr /usr/lib/librrd_th.so.* /usr/lib/libfreetype.so.* \
		/usr/lib/libart_lgpl_2.so.* /usr/lib/libgdbm.so.* \
		$(InstallLib)
	cp -rf ntop_logo.gif usr/local/share/ntop/html
	$(g_STRIP)
	find usr -name *.a -exec rm -rf {} \;
	tar -czf $(Object) usr #etc

patch:
	mv $(ObjectDir) $(ObjectDir).new
	tar xzvf $(ObjectSource)
	diff -Nur $(ObjectDir) $(ObjectDir).new > ntop-3.3.patch

clean:
	rm -rf usr $(Object) etc $(rrdObject)

dist_clean:clean
	rm -rf $(ObjectDir) $(ObjectSource) *.tar.gz *.new $(rrdObjectDir)
	
include ../Makefile.Res
